<template>
  <div class="split-line">
    <div class="text" :style="textStyles">{{ text }}</div>
    <div v-if="showExtra" class="extra">
      <slot name="extra">
        <img :src="icon" alt="icon" @click="$emit('click', $event)" />
      </slot>
    </div>
    <div v-if="lineVisible" class="line"></div>
  </div>
</template>

<script>
import icon from './assets/nor_bt_morepop.png';
export default {
  name: 'split-line',
  emits: ['click'],
  props: {
    text: { type: String, default: '标题' },
    textStyle: { type: Object, default: () => ({}) },
    lineVisible: { type: Boolean, default: true },
    icon: { type: [String, Boolean], default: icon },
  },
  computed: {
    textStyles() {
      return Object.assign({ width: this.text.length + 'em' }, this.textStyle);
    },
    showExtra() {
      return (this.icon && this.$attrs.onClick) || this.$slots.extra;
    },
  },
};
</script>

<style scoped lang="less">
.split-line {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  margin-bottom: 15px;
  font-size: 24px;
  font-weight: 700;
  color: #b1cef5;
  .text {
    flex: none;
    max-width: 70%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
  }
  .extra {
    flex: none;
    margin: 0 10px;
    cursor: pointer;
  }
  .line {
    position: relative;
    flex: auto;
    width: auto;
    min-width: 0;
    height: 0;
    border-top: 1px solid #3f4850;
    border-bottom: 1px solid #3f4850;
    &:after {
      content: '';
      position: absolute;
      top: 0;
      bottom: 0;
      right: 0;
      height: 8px;
      margin: auto;
      border-right: 2px solid #888e93;
    }
  }
}
</style>
